#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   __init__.py
@Time    :   2024-07-24 12:47:00
@Author  :   chakcy 
@Email   :   947105045@qq.com
@description   :   celery初始化
'''
import asyncio

from celery import Celery
from celery.result import AsyncResult

from app.config import config  

app = Celery("app")
app.config_from_object('app.dependencies.celery.celeryconfig')  

app.autodiscover_tasks() 

async def async_get_result(result: AsyncResult):
    """
    异步获取celery任务结果

    参数：
    - result: celery任务结果

    返回：
    - 任务执行结果
    """
    while not result.ready():
        await asyncio.sleep(1)
    finally_result = result.get()
    return finally_result

__all__ = ["app", "async_get_result"]
